<?php
/**
 * Created by PhpStorm.
 * User: a4041
 * Date: 2018/6/13
 * Time: 13:46
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Order extends Model
{
    //软删除
    use SoftDeletes;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    /*protected $fillable = [
        'user_id', 'note','shop_id', 'order_type','order_number','order_status','order_price','product_type','address_id','order_amount'
    ];*/
    protected $guarded = ['id'];
    //外卖地址
    public function OrderAddress()
    {
        return $this->belongsTo('App\Models\Address', 'address_id','id');
    }

    //打印机
    public function printers()
    {
        return $this->hasMany('App\Models\Printer', 'shop_id','shop_id');
    }
//    //商家地址
//    public function ShopInfo(){
//        return $this->hasOne('App\Models\ShopInfo', 'shop_id','shop_id');
//    }
    //订单详情
    public function OrderDetail()
    {
        return $this->hasMany('App\Models\OrderDetail', 'order_id','id');
    }

    public function Shop()
    {
        return $this->belongsTo('App\Models\Shop', 'shop_id','id')->select('id','shop_name','shop_phone','shop_avatar','shop_address','longitude','latitude');
    }

    public function ShopInfo()
    {
        return $this->belongsTo('App\Models\ShopInfo', 'shop_id','shop_id')->select('shop_id','spend','eating_time');
    }

    //预定订单表
    public function orderReserve()
    {
        return $this->hasOne('App\Models\OrderReserve','order_id','id');
    }
    public function users()
    {
        return $this->belongsTo('App\Models\User','user_id','id');
    }
    //排队订单
    public function qorder(){
        return $this->hasOne('\App\Models\OrderQueue','order_id','id');
    }
    //排队订单
    public function rorder(){
        return $this->hasOne('\App\Models\OrderReserve','order_id','id');
    }
    //扫码点餐
    public function orderscan(){
        return $this->hasOne('\App\Models\OrderScan','order_id','id');
    }
    //邀请函
    public function invitation(){
        return $this->hasOne('\App\Models\OrderInvitation','order_id','id');
    }
//    protected $appends = ['waittingtime'];       // 表里没有的字段


    // 处理订单未处理金额
//    public function getWaittingTimeAttribute()
//    {
//        $created_at = $this->attributes['created_at'];  // $this->attributes表的字段属性
////        return Carbon::now()->diffForHumans($created_at);
////        if (Carbon::now() > Carbon::parse($created_at)->addDays(100)) {
////            return Carbon::parse($created_at);
////        }
//
//        return Carbon::parse($created_at)->diffInHours();
//    }

}